/**
 * Copyright (c) 2006-2013 Las Venturas Mineground
 *
 * This program is free software: you can redistribute it and/or modify it under the terms of the
 * GNU General Public License as published by the Free Software Foundation, either version 3 of the
 * License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
 * even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License along with this program.
 * If not, see <http://www.gnu.org/licenses/>.
 */

package org.mineground;

import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.plugin.java.JavaPlugin;
import org.mineground.commands.CommandDispatcher;
import org.mineground.commands.CommandOrigin;

/**
 * The Mineground Plugin is the component which will be loaded or unloaded by the Bukkit server, and
 * thereby controls the lifetime of the Mineground Server runtime.
 */
public class MinegroundPlugin extends JavaPlugin {
    private Mineground mMinegroundInstance;

    /**
     * Called when the Mineground plugin is being enabled. Initialise a new Mineground runtime
     * and give it a pointer to this class as a JavaPlugin, given that contains too much data.
     * 
     * @see org.bukkit.plugin.java.JavaPlugin#onEnable()
     */
    @Override
    public void onEnable() {
        mMinegroundInstance = new Mineground(this);
    }
    
    /**
     * We override the command manager which has been built into Bukkit in order to give our own
     * code an ideal amount of flexibility. Our own command manager will return "false" if we aren't
     * able to handle the command, in which case another plugin gets to try.
     * 
     * @param sender Object describing who sent the command, either a Player or the console.
     * @param command The command which has been executed by this sender.
     * @param label The command as it has been typed, independent of labels.
     * @param arguments Arguments as they have been passed to the command, space separated.
     * @return A boolean indicating whether we were able to handle the command.
     */
    @Override
    public boolean onCommand(CommandSender sender, Command command, String label, String[] arguments) {
        return CommandDispatcher.Dispatch(new CommandOrigin(sender), command, label, arguments);
    }
    
    /**
     * Called when the Mineground plugin is being disabled. Shutting down the runtime will close
     * any active database connection, IRC connection or other service.
     * 
     * @see org.bukkit.plugin.java.JavaPlugin#onDisable()
     */
    @Override
    public void onDisable() {
    	mMinegroundInstance = null;
    }
}
